//
// Created by user on 2022/3/15.
//
#include <iostream>
#include <unordered_set>
using namespace std;
struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
    };
//使用hashset

ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
    //
    unordered_set<ListNode*> set;
    while (headA){
        set.insert(headA);
        headA = headA->next;
    }

    while (headB){
        if(set.count(headB))return headB;
        headB = headB->next;
    }
    return nullptr;
}